﻿using System;
using System.Collections.Generic;
using System.Text;
using XMLSettings;
using System.Threading;
using System.IO;

namespace llAma
{
    public static class Server
    {
        static Setting mServerSettings = new Setting("llama");
        public static Setting Config
        {
            get
            {
                return mServerSettings;
            }
        }
        //static bool mIsConfigDirty = false;

        //static Timer t;
        static Server()
        {
            mServerSettings.OnModify += new EventHandler<EventArgs>(Config_OnModify);
            mServerSettings.Filename = "llama.cfg";
            LoadConfig();
        }
        public static void SaveConfig()
        {
            mServerSettings.BackupPath = Path.Combine("backupConfig", "llama.cfg.bak");
            mServerSettings.Filename = "llama.cfg";
            mServerSettings.Save();
        }
        public static void LoadConfig()
        {
            try
            {
                mServerSettings.BackupPath = Path.Combine("backupConfig", "llama.cfg.bak");
                mServerSettings.Filename = "llama.cfg";
                mServerSettings.Load();
            }
            catch (System.IO.FileNotFoundException)
            {
                SaveConfig();
            }
        }
        static void Config_OnModify(object sender, EventArgs e)
        {
            SaveConfig();
        }
    }
}

